X-Git-Url: http://git.cyclocoop.org/%27%20.%20%24prefix%20.%20Wiki::transformTitleToURI%28%24matches%5B1%5D%29%20.%20%27?a=blobdiff_plain;f=includes%2Fspecials%2Fpagers%2FUsersPager.php;h=da3a30be8c184ab2fda5dd9a1727d25729ee400f;hb=ac8f144c042ae9d06f2baeb3c713afcc2a9a778a;hp=7b058c19ebda14daac9bf91bae02009f5cac8b20;hpb=47b93ded1388ce5712d0a816db4ddd3466609bcd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/pagers/UsersPager.php b/includes/specials/pagers/UsersPager.php index 7b058c19eb..da3a30be8c 100644 --- a/includes/specials/pagers/UsersPager.php +++ b/includes/specials/pagers/UsersPager.php @@ -100,7 +100,7 @@ class UsersPager extends AlphabeticPager { * @return array */ function getQueryInfo() { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $conds = []; // Don't show hidden names @@ -112,6 +112,7 @@ class UsersPager extends AlphabeticPager { if ( $this->requestedGroup != '' ) { $conds['ug_group'] = $this->requestedGroup; + $conds[] = 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ); } if ( $this->requestedUser != '' ) { @@ -177,12 +178,12 @@ class UsersPager extends AlphabeticPager { $lang = $this->getLanguage(); $groups = ''; - $groups_list = self::getGroups( intval( $row->user_id ), $this->userGroupCache ); + $ugms = self::getGroupMemberships( intval( $row->user_id ), $this->userGroupCache ); - if ( !$this->including && count( $groups_list ) > 0 ) { + if ( !$this->including && count( $ugms ) > 0 ) { $list = []; - foreach ( $groups_list as $group ) { - $list[] = self::buildGroupLink( $group, $userName ); + foreach ( $ugms as $ugm ) { + $list[] = $this->buildGroupLink( $ugm, $userName ); } $groups = $lang->commaList( $list ); } @@ -228,24 +229,32 @@ class UsersPager extends AlphabeticPager { } // Lookup groups for all the users - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $groupRes = $dbr->select( 'user_groups', - [ 'ug_user', 'ug_group' ], + UserGroupMembership::selectFields(), [ 'ug_user' => $userIds ], __METHOD__ ); $cache = []; $groups = []; foreach ( $groupRes as $row ) { - $cache[intval( $row->ug_user )][] = $row->ug_group; - $groups[$row->ug_group] = true; + $ugm = UserGroupMembership::newFromRow( $row ); + if ( !$ugm->isExpired() ) { + $cache[$row->ug_user][$row->ug_group] = $ugm; + $groups[$row->ug_group] = true; + } } + + // Give extensions a chance to add things like global user group data + // into the cache array to ensure proper output later on + Hooks::run( 'UsersPagerDoBatchLookups', [ $dbr, $userIds, &$cache, &$groups ] ); + $this->userGroupCache = $cache; // Add page of groups to link batch foreach ( $groups as $group => $unused ) { - $groupPage = User::getGroupPage( $group ); + $groupPage = UserGroupMembership::getGroupPage( $group ); if ( $groupPage ) { $batch->addObj( $groupPage ); } @@ -335,7 +344,7 @@ class UsersPager extends AlphabeticPager { function getAllGroups() { $result = []; foreach ( User::getAllGroups() as $group ) { - $result[$group] = User::getGroupName( $group ); + $result[$group] = UserGroupMembership::getGroupName( $group ); } asort( $result ); @@ -360,36 +369,30 @@ class UsersPager extends AlphabeticPager { } /** - * Get a list of groups the specified user belongs to + * Get an associative array containing groups the specified user belongs to, + * and the relevant UserGroupMembership objects * * @param int $uid User id * @param array|null $cache - * @return array + * @return array (group name => UserGroupMembership object) */ - protected static function getGroups( $uid, $cache = null ) { + protected static function getGroupMemberships( $uid, $cache = null ) { if ( $cache === null ) { $user = User::newFromId( $uid ); - $effectiveGroups = $user->getEffectiveGroups(); + return $user->getGroupMemberships(); } else { - $effectiveGroups = isset( $cache[$uid] ) ? $cache[$uid] : []; + return isset( $cache[$uid] ) ? $cache[$uid] : []; } - $groups = array_diff( $effectiveGroups, User::getImplicitGroups() ); - - return $groups; } /** * Format a link to a group description page * - * @param string $group Group name + * @param string|UserGroupMembership $group Group name or UserGroupMembership object * @param string $username Username * @return string */ - protected static function buildGroupLink( $group, $username ) { - return User::makeGroupLinkHTML( - $group, - User::getGroupMember( $group, $username ) - ); + protected function buildGroupLink( $group, $username ) { + return UserGroupMembership::getLink( $group, $this->getContext(), 'html', $username ); } - }